# usage_model.py
# usage_model.py
from datetime import date

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy import Integer, Date  # 导入 Date 类型
from ..database.db import Base  # 假设这是你的数据库基类导入方式

class Usage(Base):
    __tablename__ = 'usage_info'  # 表名为 'usage'

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    user_id: Mapped[int] = mapped_column(Integer, nullable=False)
    video_quantity: Mapped[int] = mapped_column(Integer, nullable=True)
    image_quantity: Mapped[int] = mapped_column(Integer, nullable=True)
    voice_quantity: Mapped[int] = mapped_column(Integer, nullable=True)
    ppt_quantity: Mapped[int] = mapped_column(Integer, nullable=True)
    questions_quantity: Mapped[int] = mapped_column(Integer, nullable=True)
    data: Mapped[date] = mapped_column(Date, nullable=False)  # 补全 data 字段

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

